<template>
 <view>
	<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
        <!-- 循环渲染轮播图的 item 项 -->
        <swiper-item v-for="item in banners" :key="item.goods.id" >
          <view class="swiper-item" >
            <!-- 动态绑定图片的 src 属性 -->
            <image :src="item.image_src" @click="goToDetail(item.goods_id)"></image>
          </view>
        </swiper-item>
    </swiper>
	  
	<view class="nav-list">
	  	<view class="" v-for="(item, i) in cateList" :key="i">
	  		<image class="nav-img" :src="item.image_src" mode="" @click="goJump(item.name)"></image>
	  	</view>
	</view>
	
	<!-- 楼层 item 项 -->
    <view class="floor-item" v-for="(item,index) in floors" :key="index">
        <!-- 标题部分 -->
        <image :src="item.floor_title.image_src" class="floor-title"></image>
        <!-- 标题下图片区域 -->
        <view class="floor-img-box">
			
			<!-- 左侧大图片的盒子 -->
			<navigator url="/subpkg/goods_list/goods_list" class="left-img-box">
              <image class="left-img" :src="item.product_list[0].image_src" :style="{
                width:item.product_list[0].image_width+'rpx'
              }"></image>
            </navigator>
			
            <!-- 右侧 4 个小图片的盒子 -->
            <view class="right-img-box">
              <view class="right-img-item" v-for="(item2, i2) in item.product_list" :key="i2" v-if="i2 > 0">
                <image :src="item2.image_src" :style="{
                width:item2.image_width+'rpx'
              }" mode="widthFix"></image>
              </view>
            </view>
          </view>
    </view>
 </view>
</template>


<script>
 import {getBanners,getCates, getFloors} from '@/api/home.js'
 import toast from '@/utils/toast.js'
 export default {
  data() {
	return {
		banners:[],
		cateList: [],
		floors: []
	}
  },
  onLoad() {
    this.getBanners()
	this.getCates()
	this.getFloors()
  },
  methods: {
    async getBanners() {
		const {message} = await getBanners()
		// console.log(res)
		this.banners = message
		// toast.error({
		// title:'错误'
		// })
    },
	
    goToDetail(id) {
		uni.navigateTo({
		  url:`/subpkg/goods_detail/goods_detail?id=${id}`
		})
    },
   
   async getCates() {
      const { message } = await getCates()
      console.log('message',message)
	  this.cateList = message
   },
   
   goJump(name) {
	   if(name === '分类') {
		  uni.switchTab({
		  	url:'/pages/cate/cate'
		  })
	   }
   },
   
   async getFloors() {
	   const { message } = await getFloors()
	   this.floors = message
   }
   
  }
 }
</script>

<style lang="scss">
swiper {
 height: 330rpx;

 .swiper-item,
 image {
   width: 100%;
   height: 100%;
 }
}

.nav-list {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;

  .nav-img {
    width: 128rpx;
    height: 140rpx;
  }
}

.floor-title {
  height: 60rpx;
  width: 100%;
  display: flex;
}
.right-img-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

.floor-img-box {
  display: flex;
  padding-left: 10rpx;
 .left-img {
  height: 392rpx !important;
 }
}
</style>